package org.danger.t7.common.meters;

import java.util.ArrayList;
import java.util.List;

import io.micrometer.core.instrument.Tag;
import lombok.Getter;
import lombok.Setter;

/**
 * KeyAndTags
 */
@Getter
@Setter
public final class KeyAndTags {
    private String key;
    private List<Tag> tags = new ArrayList<>();

    public static KeyAndTags key(String key) {
        KeyAndTags kt = new KeyAndTags();
        kt.key = key;
        return kt;
    }

    public KeyAndTags tag(String k, String v) {
        tags.add(Tag.of(k, v));
        return this;
    }

    public String cacheKey() {
        String ret = key;
        for (int i = 0; i < tags.size(); i++) {
            ret += "-" + tags.get(i).getKey() + ":" + tags.get(i).getValue();
        }
        return ret;
    }
}
